package com.shhic.hhplt.server.bkgrdui;

import javax.annotation.Resource;

import com.shhic.hhplt.server.service.IDashboardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.shhic.hhplt.server.biz.IDashboardInfoContainer;
import com.shhic.hhplt.server.model.Dashboard;
import com.shhic.hhplt.server.model.DashboardInfo;

/**
 * 电子公示板门面
 * 用于电子公示板Web界面的请求，该Controller不受Session的控制
 * @author user
 */
@Controller
@RequestMapping("/dashboard")  
public class DashboardController {

	@Resource IDashboardInfoContainer dashboardInfoContainer;
	@Autowired
	IDashboardService dashboardService;

	/**
	 * 进入电子公示板
	 * @param boardName	URL参数，公示板名称
	 * @return
	 */
	@RequestMapping(value = "/enterDashboard.do", method = RequestMethod.GET,produces = "text/json;charset=UTF-8")
	public ModelAndView enterDashboard(@RequestParam String boardName){
		Dashboard dashboard = dashboardService.getDashboard(boardName);
		return dashboard == null ? new ModelAndView("forward:noDashboardError.html"): new ModelAndView("/dashboard/template/"+dashboard.getTemplateFileName());
	}
	
	/**
	 * 获得公示板信息
	 * @param boardName
	 * @return
	 */
	@RequestMapping(value = "/getDashboardInfo.do", method = RequestMethod.GET,produces = "application/json;charset=UTF-8")
	@ResponseBody
	public DashboardInfo getDashboardInfo(@RequestParam String boardName){
		DashboardInfo dashboardInfo = dashboardInfoContainer.getDashboardInfo(boardName);
		return dashboardInfo == null ? DashboardInfo.emptyDashboardInfo(boardName) : dashboardInfo;
	}
}




